<?php
define('SSLIB_User', TRUE);
define('sslib_user_object', 'sslibuserobject');

/**
 * User information handler. Get it by user id
 *
 */
class User
{
	private $id = null;
	private $arr = array();
	function __construct($id)
	{
		$this->id = $id;
		if(!Sslib::Debug() && array_key_exists(sslib_user_object, $_ENV))
			$this->arr = $_ENV[sslib_user_object];
		else
			$this->Update();
	}
	function Update()
	{
		$groups = Sslib::TableGroups();
		$users = Sslib::TableUsers();
		$group = Sql::Quote('group', false);
		
		if($this->id)
			$this->arr = Sslib::DB()->QueryToArray(
			"SELECT 
				(SELECT name FROM $groups WHERE id = u.groupid) as $group,
				nick,email, groupid FROM $users AS u WHERE id = ".$this->id);
			
		else
			$this->arr = array('nick'=>'','group'=>'','groupid'=>'','email'=>'');
		$_ENV[sslib_user_object] = $this->arr;
	}
	function Nick(){return $this->arr['nick'];}
	function Group(){return $this->arr['group'];}
	function GroupID(){return $this->arr['groupid'];}
	function Email(){return $this->arr['email'];}
}

?>